package com.netstar.property;

import java.io.IOException;

import org.json.JSONException;

public abstract class BooleanProperty extends PrimitiveProperty {
	public abstract void set(Property obj, boolean val);

	public abstract boolean get(Property obj);

	public BooleanProperty() {
	}

	@Override
	public void copy(Property lhs, Property rhs) {
		set(lhs, get(rhs));
	}

	@Override
	public void parse(Property obj, Object value) throws JSONException,
			IOException {
		if (value == null) {
			set(obj, false);
		} else {
			String t = value.toString().trim();
			if (t.equalsIgnoreCase("true") || t.equalsIgnoreCase("1")
					|| t.equalsIgnoreCase("YES")) {
				set(obj, true);
			} else {
				set(obj, false);
			}
		}
	}

}
